﻿namespace Acoris.Foundation
{
    /// <summary>
    /// 表示位置
    /// </summary>
    public struct Position
    {
        public static readonly Position OriginPosition = new Position(0,0,0);

        /// <summary>
        /// 使用指定的坐标初始化当前位置
        /// </summary>
        /// <param name="x">x轴的位置</param>
        /// <param name="y">y轴的位置</param>
        /// <param name="z">z轴的位置</param>
        public Position(float x,float y,float z)
        {
            X = x;
            Y = y;
            Z = z;
        }

        /// <summary>
        /// 获取或设置X轴的位置
        /// </summary>
        public float X { get; set; }

        /// <summary>
        /// 获取或设置Y轴的位置
        /// </summary>
        public float Y { get; set; }

        /// <summary>
        /// 获取或设置Z轴的位置
        /// </summary>
        public float Z { get; set; }

        #region Override

        /// <summary>
        /// 获取与当前对象等价的字符串形式
        /// </summary>
        /// <returns>返回与当前对象等价的字符串形式</returns>
        public override string ToString()
        {
            return $"{X},{Y},{Z}";
        }

        /// <summary>
        /// 获取当前对象与指定对象之间的等价性
        /// </summary>
        /// <param name="obj">指定要比较的对象</param>
        /// <returns>如果两个对象之间等价则返回true，否则返回false</returns>
        public override bool Equals(object obj)
        {
            if(obj is Position pos) {
                return pos.X == this.X && pos.Y == this.Y && pos.Z == this.Z;
            }
            return false;
        }

        /// <summary>
        /// 获取当前对象的哈希值
        /// </summary>
        /// <returns>返回当前对象的哈希值</returns>
        public override int GetHashCode()
        {
            return X.GetHashCode() ^ Y .GetHashCode() ^ Z.GetHashCode();
        }
        #endregion

        #region operator == / !=

        public static bool operator !=(Position x, Position y)
        {
            return x.X != y.X || x.Y != y.Y || x.Z != y.Z;
        }

        public static bool operator ==(Position x, Position y)
        {
            return x.X == y.X && x.Y == y.Y && x.Z == y.Z;
        }

        #endregion
    }
}
